Skip to content

Conversation

@seratch
Copy link
Member

@seratch seratch commented Jun 25, 2025

This pull request resolves #604; just checking the existence of the data and avoiding the runtime exception should make sense.

@seratch seratch requested a review from rm-openai June 25, 2025 01:15
@seratch seratch added bug Something isn't working feature:chat-completions labels Jun 25, 2025
@seratch
Copy link
Member Author

seratch commented Jun 25, 2025

now this is ready for reviews

@seratch seratch force-pushed the issue-604-chat-completions-runtime-error branch from 951b9c7 to 403aeea Compare June 25, 2025 23:26
@seratch seratch merged commit 94f8035 into main Jun 25, 2025
5 checks passed
@seratch seratch deleted the issue-604-chat-completions-runtime-error branch June 25, 2025 23:28
gn00295120 pushed a commit to gn00295120/openai-agents-python that referenced this pull request Oct 22, 2025
Add defensive checks before accessing response.choices[0] to prevent
IndexError when Gemini or other providers return an empty choices array.

This follows the same pattern as PR openai#935 which fixed the identical issue
in openai_chatcompletions.py.

Changes:
- Add null checks for response.choices before array access
- Return empty output when choices array is empty
- Preserve usage information even when choices is empty
- Add appropriate type annotations for litellm types
gn00295120 pushed a commit to gn00295120/openai-agents-python that referenced this pull request Oct 24, 2025
Add defensive checks before accessing response.choices[0] to prevent
IndexError when Gemini or other providers return an empty choices array.

This follows the same pattern as PR openai#935 which fixed the identical issue
in openai_chatcompletions.py.

Changes:
- Add null checks for response.choices before array access
- Return empty output when choices array is empty
- Preserve usage information even when choices is empty
- Add appropriate type annotations for litellm types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:chat-completions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SDK crashes when choices is None (provider-error payload)

2 participants